<!--  项目在线评审列表 -->
<template>
  <vxe-modal class-name="rk-modal rk-projsort-modal"
    resize
    transfer
    show-zoom
    fullscreen
    destroyOnClose
    v-model="visible"
    width="1000"
    height="600"
    :z-index="1002"
    min-width="460"
    min-height="320"
    @close="handleClose">
    <template #title>
      <div w-xs>任务名称: 暂无</div>
    </template>
    <template #default>
      <RkContainer :isFooter="false"
        :isAside=false
        v-show="!loading">
        <template #header_left></template>
        <template #header_right>
          <el-button type="primary"
            @click="handleConfirm">保存</el-button>
          <el-button type="danger"
            @click="handleClose">取消</el-button>
          <el-button type="primary"
            @click="handleBack">返回任务列表</el-button>
        </template>
        <template #main>
          <rk-condition>
            <template #content>
              <rk-grid ref="projSortList"
                class="rk-projsort-table"
                dataUrl="/reviewtask/page"
                boxConfig
                :params="queryParams"
                :columns="tableColumns">
                <template #operation="{ row }">
                  <div class="operation-box">
                    <el-button type="primary"
                      link
                      @click.stop="handleOperation('preview',row)">预览</el-button>
                    <el-button type="primary"
                      link
                      @click.stop="handleOperation('load',row)">下载</el-button>
                  </div>
                </template>
                <template #opinion="{ row }">
                  <div class="operation-box">
                    <el-button type="primary"
                      link
                      @click.stop="handleOperation('add',row)">添加</el-button>
                  </div>
                </template>
                <template #proNum="{ row }">
                  <div class="operation-box">
                    <el-button type="primary"
                      link
                      @click.stop="handleOperation('score',row)">{{ row.proNum }}</el-button>
                  </div>
                </template>
              </rk-grid>
            </template>
          </rk-condition>
        </template>
      </RkContainer>
      <ReserveProjNoteDialogView v-model:visible="noteVisible"
        :ok="dialogOkClick" />
      <ExpertRatingList ref="expertRatingRef" />
      <ReviewReportDrawer ref="reviewReportRef" />
    </template>
  </vxe-modal>
</template>
<script setup>
import ReserveProjNoteDialogView from "../dialogs/ReserveProjNoteDialogView.vue";
import ExpertRatingList from "./ExpertRatingList.vue";
import ReviewReportDrawer from "./ReviewReportDrawer.vue"
import { reserveProHandleTask } from "@/api/api-project";

const { appContext } = getCurrentInstance();
const globalProxy = appContext.config.globalProperties;
const emit = defineEmits(['agNodeClick'])
const projSortList = ref('')
let leaf = ref(false)
// 查询参数
let queryParams = reactive({
  wfStatus: '001',
  status: undefined,
  mhcx: undefined,
  bondTypeCode: 1,    // 债券类型测试数据 1、一般 2、专项
  nodeId: 'node_1',  //填报测试数据
  processKey: 'PRO_CBK', //测试数据
  adCode: '2300', //'321005'
  agCode: undefined,
  agId: undefined,
  dw: 2
})

const auditParams = reactive({
  applyIds: '',
  proIds: '',
  taskIds: '',
  note: '',
  taskType: ''
})

// ----- 弹窗相关操作
// 是否展示弹窗
const visible = ref(false)
// 是否加载中
const loading = ref(false)
// 提交的参数-也是传递的参数
const submitParams = ref({})
// 表单回显数据
const echoFormData = ref({})
// 打开加载中
const openLoading = ref({})
// 是否展示意见弹窗
const noteVisible = ref(false)
// 专家评分弹窗
const expertRatingRef = ref('')
// 项目评审详情弹窗
const reviewReportRef = ref('')

const tableColumns = ref([
  { field: 'setupYear', title: '地区', width: 150 },
  { field: 'agencyName', title: '单位', width: 100 },
  { field: 'fundInvestAreaCode', title: '项目编码', width: 150 },
  { field: 'totalBudget', title: '项目名称', width: 200, align: 'right' },
  { field: 'proStatusName', title: '项目负责人', width: 100 },
  { field: 'startDate', title: '所有专家评审结论（是否满足发债要求）', width: 150 },
  { field: 'endDate', title: '机构终审结论（是否满足发债要求）', width: 150 },
  { field: 'proNum', title: '项目总得分', width: 150, slots: { default: 'proNum' } },
  { field: 'opinion', title: '项目终审意见', width: 150, slots: { default: 'opinion' } },
  { field: 'operation', title: '评审报告', width: 150, align: 'center', showOverflow: true, slots: { default: 'operation' } }
])

/**查询 */
const handleSearch = () => {
  projSortList.value.searchEvent()
}

/**
 * 打开弹窗
 * @param {Object} config 配置信息
 */
const handleOpen = async (config) => {
  visible.value = true
  if (config.buttonCode === 'edit') {
  }
}
/**
 * 关闭弹窗
 */
const handleClose = () => {
  handleReset()
}
/**
 * 返回已终审列表
 */
const handleBack = () => {
  handleReset();

}
/**
 * 重置数据
 */
const handleReset = () => {
  visible.value = false
  loading.value = false
}

/**
 * 保存功能
 */
const handleConfirm = () => { }
/**
 * 打开送审弹窗
 * @param {Object} config 参数配置
 */
const handleEdit = (config = {}) => {
  // 设置模式为可编辑模式
  config['buttonCode'] = 'edit'
  console.log(config)
  // 打开弹窗
  handleOpen(config)
}

const handleView = (config = {}) => {
  // 设置模式为查看模式
  config['buttonCode'] = 'detail'
  // 打开弹窗
  handleOpen(config)
}

// ----- emits相关调用
const emitRefresh = () => {
  emits('refresh')
}

const handleOperation = async (buttonType, rowData) => {
  if (buttonType == 'preview') { //预览
    reviewReportRef.value.handleOpen()
  }
  if (buttonType == 'load') { //下载
  }
  if (buttonType == 'add') { //添加
    noteVisible.value = true
  }
  if (buttonType == 'score') { //专家评分情况
    expertRatingRef.value.handleOpen()
  }
}

/**
 * 审核
 * @param note
 */
const dialogOkClick = async (note) => {
  auditParams.note = note
  auditParams.taskType = WF_TASK_AUDIT.value
  const resp = await reserveProHandleTask(auditParams)
  visible.value = false
  const { code, msg } = resp
  if (code === 200) {
    globalProxy.$message({ message: `审核成功！`, type: "success" });
    handleSearch()
  } else {
    globalProxy.$message({ message: `${msg}`, type: "error" });
  }

}


// 对外暴露方法
defineExpose({
  handleView,
  handleEdit,
})


</script>

<style lang="scss" scoped>
.operation-box {
  display: flex;
  justify-content: space-around;
}
</style>